/**
 * Created by guojianyu on 2016/3/24.
 */
myApp.config(function ($routeProvider) {
    $routeProvider.when('/business/view', {
        templateUrl: 'business/view',
        controller: 'businessController'
    })
});
myApp.service('businessListService', function ($http) {
    var doRequest = function () {
        return $http.get('business/list');
    }
    return {
        businessList: function () {
            return doRequest();
        }
    };
});
myApp.controller('businessController', function ($scope, $location, $http, businessListService,Notify) {
    /*获取表单数据*/
    businessListService.businessList().success(function (response) {
        $scope.businesses = response;
        $scope.status = $scope.businesses[0].status == "enabled" ? true : false;
    });
    /*返回登录页*/
    $scope.return=function() {
        window.location.href = "/web/"
    }
    /*更新商家*/
    $scope.update=function(data){
        $scope.business=angular.copy(data);
    };
    $scope.updateBusiness = function () {
        $scope.businesses=angular.copy($scope.business);
        $http.post('business/update', $scope.businesses).success(function () {
            Notify.success("更新商家成功");
            businessListService.businessList().success(function (response) {
                $scope.businesses = response;
            });
        }).error(function () {
            Notify.error('失败');
        });
    };
});

